package pdai.a2_多线程;

public class race implements Runnable {
    private String winner;

    @Override
    public void run() {
        for (int i = 1; i <= 101; i++) {
            boolean flag=gameOver(i);
            if (flag){
                break;
            }
                if (i<=100){
                    System.out.println(Thread.currentThread().getName()+"走了"+i+"步");
                }
            }

        }


    private boolean gameOver(int i) {
        if (i>=100) {
            winner = Thread.currentThread().getName();
            System.out.println(winner + "是获胜者");
            return true;
        }
        return false;

    }

    public static void main(String[] args) {
        race ra=new race();
        new Thread(ra,"兔子").start();
        new Thread(ra,"乌龟").start();

    }
}
